package models

import (
	"time"

	"github.com/google/uuid"
	"gorm.io/gorm"
)

type GameResult struct {
	ID         string    `gorm:"primaryKey;type:varchar(255)" json:"id"`
	GameCode   string    `gorm:"type:varchar(255);not null" json:"gameCode"`
	Dice1      int       `gorm:"type:int;not null" json:"dice1"`
	Dice2      int       `gorm:"type:int;not null" json:"dice2"`
	Dice3      int       `gorm:"type:int;not null" json:"dice3"`
	Sum        int       `gorm:"type:int;not null" json:"sum"`
	ResultTime time.Time `gorm:"type:timestamp;not null" json:"resultTime"`
	CreatedAt  time.Time `gorm:"type:timestamp" json:"created_at"`
	UpdatedAt  time.Time `gorm:"type:timestamp" json:"updated_at"`
	Status     int       `gorm:"type:int;not null;default:0" json:"status"`
	Bets       []*Bet    `gorm:"many2many:bet_game_result; constraint:OnDelete:CASCADE" json:"bets"`
}

func (game_result *GameResult) TableName() string {
	return "game_result"
}

func (game_result *GameResult) BeforeCreate(tx *gorm.DB) error {
	game_result.ID = uuid.NewString()
	game_result.CreatedAt = time.Now()
	game_result.UpdatedAt = time.Now()
	return nil
}

func (game_result *GameResult) BeforeUpdate(tx *gorm.DB) error {
	game_result.UpdatedAt = time.Now()
	return nil
}
